package com.rustic.server.controller.api;

import cn.xy.commons.core.Result;
import com.rustic.server.dto.InteractionDataDTO;
import com.rustic.server.po.UserCollectionLink;
import com.rustic.server.po.UserLikeLink;
import com.rustic.server.service.UserCollectionLinkService;
import com.rustic.server.service.UserLikeLinkService;
import com.rustic.server.vo.UserInteractionStatusVO;
import com.rustic.server.web.WebContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户行为数据公用接口接口
 *
 * @author auto
 */

@Slf4j
@RestController
@RequestMapping("/api/userInteraction")
@Api(tags = {"用户行为数据公用接口接口"})
public class UserInteractionController {

    @Autowired
    private UserCollectionLinkService userCollectionLinkService;

    @Autowired
    private UserLikeLinkService userLikeLinkService;

    @ApiOperation(value = "用户点赞收藏情况")
    @GetMapping("/getInteractionStatus")
    public Result<UserInteractionStatusVO> getInteractionStatus(@Validated InteractionDataDTO interaction) {
        int userId = WebContext.getUserId();
        UserInteractionStatusVO interactionStatus = new UserInteractionStatusVO();
        UserCollectionLink userCollectionLink = userCollectionLinkService.getByUserTargetAndType(userId, interaction.getTargetId(), interaction.getType());
        UserLikeLink userLikeLink = userLikeLinkService.getByUserTargetAndType(userId, interaction.getTargetId(), interaction.getType());
        if (userCollectionLink != null) {
            interactionStatus.setCollection(true);
        }
        if (userLikeLink != null) {
            interactionStatus.setLike(true);
        }
        return Result.data(interactionStatus);
    }
}
